# 在cifar10上训练

import keras
from keras.api.datasets import cifar10
from keras.api.datasets import cifar100
from keras.src.optimizers import Adam

import myNet01

num_classes = 10

(x_train, y_train), (x_test, y_test) = cifar10.load_data()
(x_train, y_train), (x_test, y_test) = cifar100.load_data()
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0
# y_train = keras.api.utils.to_categorical(y_train, num_classes)
# y_test = keras.api.utils.to_categorical(y_test, num_classes)

# 如果你使用的是CIFAR-10数据集，你需要将输入大小设置为(32, 32, 3)，类别数设置为10。
m = myNet01.create_alexnet(input_shape=(32, 32, 3), num_classes=num_classes)
m.compile(optimizer=Adam(), loss='sparse_categorical_crossentropy', metrics=['accuracy'])

m.fit(x_train, y_train, epochs=10, batch_size=64, validation_data=(x_test, y_test))

test_loss, test_acc = m.evaluate(x_test, y_test)
print(f'Test accuracy: {test_acc}')

print(444)